{php}$namespace = ns();{/php}
<script>
    Namespace.register("EBCMS.Forms");
    $(function(){
        EBCMS.Forms.FormSubmit = function FormSubmit(){
            EBCMS.CORE.submit({
                url:'{:url('user/admin.group/menu')}',
                form:'{$namespace}Form',
                success:function(data){
                    EBCMS.MSG.notice('提交成功！');
                    $('#lgModal').modal('hide');
                    EBCMS.{$namespace}.refresh();
                }
            });
        };
        EBCMS.CORE.load({
            url: '{:url('user/admin.group/menu')}',
            queryParams:{
                group_id:'{:input('id')}',
                __type:'menu',
            },
            tree:true,
            treelevel:true,
            tpl:'{$namespace}-menu',
            target:'#{$namespace}-menu_main',
            compileAfter:function(p){
                $('input[name="menu_ids\[\]"]').bind('click', function(event) {
                    var checked = $(this).is(':checked');
                    /*子级别改变*/
                    $(this).parent('li').next().find('ul input').prop('checked',checked)
                    /*如果是选中 则主线选中*/
                    if (checked) {
                        EBCMS.CORE.checkpar($(this).parent().parent().parent());
                    }
                });
            }
        });
        EBCMS.CORE.checkpar = function(dom){
            var x = dom.prev();
            if (x.is('li')) {
                x.children('input').prop('checked',true);
                EBCMS.CORE.checkpar(x.parent().parent());
            }
        };
    });
</script>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">分配功能</h4>
</div>
<div class="modal-body">
    <form action="" id="{$namespace}Form">
        <div id="{$namespace}-menu_main"></div>
        <input type="hidden" name="group_id" value="{:input('id')}">
    </form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-primary" onclick="EBCMS.Forms.FormSubmit();">提交</button>
    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
<script id="{$namespace}-menu" type="text/html">
    <form id="{$namespace}menuform">
        <ul class="list-group tree tree_first" style="border-top: 1px solid #ddd;border-right: 1px solid #ddd;border-bottom: 1px solid #ddd;">
            [[include '{$namespace}-menu-item']]
        </ul>
    </form>
</script>
<script id="{$namespace}-menu-item" type="text/html">
    [[each rows as v n]]
        <li class="list-group-item">
        <input type="checkbox" name="menu_ids[]" value="[[v.id]]" id="{$namespace}_menu_item_[[v.id]]" [[if v.checked]]checked="checked"[[/if]]>
            <label for='{$namespace}_menu_item_[[v.id]]'>[[v.title]]</label>
        </li>
        [[if v.rows]]
        <li class="list-group-item nopadding">
            <ul class="list-group tree">
                [[include '{$namespace}-menu-item' v]]
            </ul>
        </li>
        [[/if]]
    [[/each]]
</script>